import React from 'react';
import { connect } from 'dva';
import styles from './mine_all.less';
import { getData,addSessionData } from '../../../utils/localData'
import MyJRoll from '../../../utils/MyJRoll/Yr.js'
import TopLoading from '../../../utils/MyJRoll/topLoading'
import OrderItem from './order_item'
import { NavBar, Icon } from 'antd-mobile';
import moment from 'moment'

@connect(({orders}) => ({
  orders
}))

export default class Mine_all extends React.Component {
  render() {
     document.title = '全部订单'
    console.log("我的全部订单")
    console.log(this.props.orders.orderList)
    const rheight = document.documentElement.clientHeight +"px"
    let {orderList} = this.props.orders;
    let list = []
    if(orderList.orderList){
      orderList.orderList.map((item,i) => {
        list.push(
          <OrderItem key={i} index={i} history={this.props.history} order={item} dispatch={this.props.dispatch}/>
        )
      })
    }


    return (
      <div style={{height:'100%'}}>

         {/*<NavBar
            mode="light"
            icon={<Icon type="left" onClick={() => { this.props.history.goBack() }} />}
            onLeftClick={() => console.log('onLeftClick')}>全部订单
         </NavBar>*/}

          <MyJRoll
            height={rheight}
            topMax={50}
            bottomMax={-50}
            topf={50}
            bounce = {true}
            topLoading={<TopLoading/>}
            topFr={this.selOrderFlash.bind(this)}
            bottomFr={this.selOrderAdd.bind(this)}
          >
            <div>
              {list}
            </div>
          </MyJRoll>
     </div>
    )
  }
  componentDidMount(){
    this.selOrder()
  }

  selOrderFlash(){
    this.selOrder()
  }
  selOrderAdd(){
    this.selOrder(true)
  }

  selOrder(add){
    console.log(add)
    const { dispatch } = this.props
    let user = JSON.parse(getData("userInfo"));
    if(add){
      let page = this.props.orders.orderList.page+1;
      if(page > this.props.orders.orderList.totalPage){
        return
      }
      dispatch({
          type: 'orders/selOrderList',
          payload: {userId:user.userId,page:page,pageSize:this.props.orders.orderList.pageSize}
      })
    }else{
      dispatch({
        type: 'orders/selOrderList',
        payload: {userId:user.userId,page:1,pageSize:10}
      })
    }
  }
}
